#!/bin/bash

update="$(/usr/sbin/slackpkg check-updates)"
update="$(echo $update | grep 'No news is good news')"

version="$(cat /etc/slackware-version | cut -d' ' -f2)"
arch="$(uname -m)"
mirror="http://mirrors.slackware.com/slackware/slackware"
end="$(grep -n '+--------------------------+' /tmp/changelog.txt | head -n1 | cut -d':' -f1)"
changelog="$(head -n$end /tmp/changelog.txt  | grep txz | cut -d'/' -f2 | cut -d':' -f1)"
num_changelog="$(head -n$end /tmp/changelog.txt  | grep txz | cut -d'/' -f2 | cut -d':' -f1 | wc -l)"

if [ "$version" == "14.2" ]
then
    version="current"
fi

if [ "$arch" == "x86_86" ]
then
    arch="64"
else
    arch=""
fi

case $BLOCK_BUTTON in
    1) notify-send -u low "`echo "$changelog"`" ;;
    3) notify-send -u low "`echo "$changelog"`" ;;
esac

wget -q -O - $mirror$arch-$version/ChangeLog.txt | iconv -f ISO-8859-1 -t UTF-8 > /tmp/changelog.txt

if [ -z "$update" ]
then
    echo -n "<span foreground='#729FCF'>&#xf021;</span>  `echo $num_changelog` Updates"
else
    echo -n "<span foreground='#729FCF'>&#xf021;</span>  No Updates"
fi

exit 0
